﻿Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Public Class FormReportEnrolmentDetail

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql = "SELECT s.STUDENT_CODE,s.NAME,s.SEX,s.BIRTH_DATE,p.PROVINCE_NAME,j.SUBJECT_CODE,j.SUBJECT_NAME,j.TYPE, e.RIGISTER_DATE,e.PRICE   FROM TBL_ENROLL e INNER JOIN TBL_STUDENT s ON e.STUDENT_CODE=s.STUDENT_CODE  INNER JOIN TBL_SUBJECT j ON e.SUBJECT_CODE=j.SUBJECT_CODE INNER JOIN TBL_PROVINCE p ON p.PROVINCE_CODE=s.PROVINCE_CODE " & _
                " WHERE UPPER(s.STUDENT_CODE+s.NAME+j.SUBJECT_CODE+j.SUBJECT_NAME) LIKE UPPER('%" & txtSearch.Text & "%') " & _
                " AND e.RIGISTER_DATE BETWEEN '" & Me.dtp1.Value.ToString("yyyy-MM-dd") & "' AND '" & Me.dtp2.Value.AddDays(1).ToString("yyyy-MM-dd") & "'  "

        Dim cn As New SqlConnection("server=.;uid=sa;pwd=123;database=SchoolDb;")
        cn.Open()
        Dim cmd As New SqlCommand(sql, cn)
        Dim dr = cmd.ExecuteReader()
        Dim dt As New DataTable()
        dt.Load(dr)
        dr.Close()
        Dim reportName As String = "SchoolApp.ReportEnrollmentDetail.rdlc"

        If rdoDetail.Checked Then
            reportName = "SchoolApp.ReportEnrollmentDetail.rdlc"
        End If
        If rdoSummaryGroup.Checked Then
            reportName = "SchoolApp.ReportEnrollmentSummaryGroup.rdlc"
        End If
        If rdoSummaryCrosstab.Checked Then
            reportName = "SchoolApp.ReportEnrollmentSummaryMatrix.rdlc"
        End If


        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("SchoolDataSet_DATA_ENROLL", dt))
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = reportName

        Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
        Me.ReportViewer1.ZoomMode = ZoomMode.Percent
        Me.ReportViewer1.ZoomPercent = 100

        Me.ReportViewer1.RefreshReport()
         
    End Sub

    Private Sub rdoSummaryGroup_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoSummaryGroup.CheckedChanged

    End Sub
End Class